package com.justgame.project.base.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class WrapperBuilder {

    public static <V,E> V build(E entity,Class<V> clazz){
        V vo = BeanUtils.instantiateClass(clazz);
        BeanUtils.copyProperties(vo,entity);
        return vo;
    }

    public static <V,E> List<V> build(List<E> entities, Class<V> clazz){
        List<V> vos = new ArrayList<V>(entities.size());
        entities.forEach( e -> {
            vos.add(build(e,clazz));
        });
        return vos;
    }
}
